<template>
  <div class="check">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">协助发货管理</span>
        <el-button style="float: right;" type="success" @click="dialogUploadOpen" v-if>导入订单</el-button>
      </div>
      <s-table
        :table="table"
        :expand="true"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          width="150"
          label="可用操作">
          <template slot-scope="s">

            <el-popover
              popper-class="demo-table-expand"
              placement="right"
              title="更多可用操作"
              trigger="click">
              <slot name="content">
                <el-button type="info"  size="mini" @click="tablePrint(s.row)">打印装车单</el-button>
                <el-button type="info"  size="mini" @click="dialogCreateOpen(s.row)"  v-if="s.row.zcdbh ==='0'">创建装车单</el-button>
                <el-button type="warning"  size="mini" @click="tableShipment(s.row)" v-if="s.row.xfzt == '0'">发运</el-button>
                <el-button type="success"  size="mini" @click="tableAdditionalShipment(s.row)" v-if="s.row.fyzt =='3'">追加发运</el-button>
                <el-button type="info" size="mini" @click="dialogIssuedOpen(s.row)" v-if="s.row.xfzt =='0'">下发PDA任务</el-button>
                <el-button type="info" size="mini" @click="dialogSearchOpen(s.row)" v-if="(s.row.zt =='1' || s.row.zt =='2') && (s.row.fyzt =='1' || s.row.fyzt =='2' || s.row.fyzt =='3')">查看下发</el-button>
                <el-button type="info" size="mini" icon="edit"  @click="dialogEditOpen(s.row)" v-if="s.row.zcdbh ==='0' && s.row.xfzt ==='0'"></el-button>
                <el-button type="info" size="mini" @click="helpWeight(s.row)">协助称重</el-button>
                <el-button type="danger" size="mini" icon="delete" @click="tableDelete(s.row)"></el-button>
              </slot>
              <el-button slot="reference" type="info" icon="more" :plain="true" size="mini" class="__reference"></el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="table.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button type="success" size="small" @click="tableShipment('')">发运</el-button>
            </el-col>
            <el-col  :span="8">
              <el-button type="warning" size="small" @click="dialogMultiOpen">多选装车单</el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="danger" @click="tableDelete()" >删除</el-button>
            </el-col>
            <el-col :span="8">
              <el-button type="info" size="small" @click="tablePrint('')">打印装车单</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="订单号" prop="ddh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_ddh"
                    placeholder="订单号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="装车编号" prop="zcdbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_zcdbh"
                    placeholder="装车编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="下发状态" prop="xfzt">
          <el-select v-model="autoVue_table_xfzt"
                     placeholder="下发状态">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in ASSISTGOODS.xfzt"
              :key="item.dictionaryid"
              :label="item.value"
              :value="item.dictionaryid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="流水号" prop="lsh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_lsh"
                    placeholder="流水号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="发起人" prop="fqr">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_fqr"
                    placeholder="发起人" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
      </s-table>
    </el-card>
    <s-dialog :dialog="dialogUpload" :close="dialogUploadInit" :closeTip="false">
      <p slot="title">导入订单</p>
      <el-upload
        ref="upload"
        name="zxwms_shipment"
        :action="action"
        :show-file-list="true"
        :before-upload="dialogUploadBefore"
        :on-success="dialogUploadSuccess"
        :on-error="dialogUploadError"
        :auto-upload="false">
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="success" @click="dialogUploadSubmit">上传到服务器</el-button>
        <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
      </el-upload>
      <el-button slot="footer" @click="dialogUploadSave">好</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogEdit" :close="dialogEditInit">
      <p slot="title">{{dialogEdit.title}}承运信息</p>
      <s-form :form="formDialogEdit" ref="formDialogEdit">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="kddh" label="快递单号">
              <el-input
                type="text"
                v-model="formDialogEdit.kddh"
                placeholder="快递单号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="fhfs" label="承运商">
              <el-input
                type="text"
                v-model="formDialogEdit.fhfs"
                placeholder="承运商"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="yf" label="运费">
              <el-input
                type="text"
                v-model="formDialogEdit.yf"
                placeholder="运费"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="sjzl" label="实际重量">
              <el-input
                type="text"
                v-model="formDialogEdit.sjzl"
                placeholder="实际重量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="bz" label="备注">
              <el-input
                type="text"
                v-model="formDialogEdit.bz"
                placeholder="备注"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogEditSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogHelpWeight" :close="dialogInit">
      <p slot="title">{{dialogHelpWeight.title}}</p>
      <s-form :form="formDialog1" ref="formDialog1">
        <el-row>
          <el-col :xs="24" :lg="{span: 5, offset: 0}">
            <el-form-item prop="dzc" label="电子秤">
              <el-select v-model="dzcselect" v-on:change="selectchange" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 3, offset: 1}">
            <el-form-item prop="sjzl" label="实际重量">
              <el-input
                type="text"
                ref="sjzl"
                v-on:change="sjzlchange"
                v-model="sjzlinput"
                @keyup.enter.native="sjzlchange"
                placeholder="实际重量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}">
            <el-form-item prop="cyslb" label="快递">
              <el-select v-model="cyslb" placeholder="请选择">
                <el-option
                  label="申通"
                  value="申通"></el-option>
                <el-option
                  label="圆通"
                  value="圆通"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 3, offset: 1}">
            <el-button style="margin-top:36px;float: right;" type="primary" @click="printpaper">打印快递面单</el-button>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogInit">确定</el-button>
    </s-dialog>
    <!--弹出-->
    <s-dialog :dialog="dialogCreate" :close="dialogCreateInit">
      <p slot="title">{{dialogCreate.title}}承运人</p>
      <s-form :form="formDialogCreate" ref="formDialogCreate">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="cyrmc" label="承运人">
              <el-select v-model="formDialogCreate.cyrmc"
                         filterable
                         remote
                         placeholder="请选择承运人"
                         @change="dialogRemoteCyrid"
                         :remote-method="dialogRemoteCyrmc">
                <el-option
                  v-for="item in dialogCreate.wmsloading"
                  :key="item.cyrid"
                  :label="item.cyrmc"
                  :value="item.cyrid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="cycl" label="承运车辆">
              <el-select v-model="formDialogCreate.cycl"
                         filterable
                         remote
                         @change="dialogRemoteCyclid"
                         :remote-method="dialogRemoteCycl"
                         placeholder="请选择承运车辆">
                <el-option
                  v-for="item in dialogCreate.searchCph"
                  :key="item.cyclid"
                  :label="item.cycl"
                  :value="item.cyclid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogCreateSave">保存</el-button>
    </s-dialog>
    <!--新增 下发发运任务-->
    <s-dialog :dialog="dialogIssued" :close="dialogIssuedInit">
      <p slot="title">{{dialogIssued.title}}PDA任务</p>
      <s-form :form="formDalogIssued" ref="formDalogIssued">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="account" label="账户类型">
              <el-select v-model="formDalogIssued.account" placeholder="请选择">
                <el-option
                  v-for="item in SHELVESTASK.account"
                  :key="item.dictionaryid"
                  :label="item.value"
                  :value="item.dictionaryid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="ryid" label="人员">
              <el-select v-model="formDalogIssued.ryid"
                         filterable
                         placeholder="请输入人员名称">
                <el-option
                  v-for="item in dialogIssued.wmsqualityinspectionlist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogIssuedSave">保存</el-button>
    </s-dialog>
    <!-- 创建装车单-->
    <s-dialog :dialog="dialogMulti" :close="dialogMultiInit">
      <p slot="title">{{dialogMulti.title}}承运人</p>
      <s-form :form="formDialogMulti" ref="formDialogMulti">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="cyrmc" label="承运人">
              <el-select v-model="formDialogMulti.cyrmc"
                         filterable
                         remote
                         placeholder="请选择承运人"
                         @change="dialogRemoteCyrid"
                         :remote-method="dialogRemoteCyrmc">
                <el-option
                  v-for="item in dialogCreate.wmsloading"
                  :key="item.cyrid"
                  :label="item.cyrmc"
                  :value="item.cyrid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="cycl" label="承运车辆">
              <el-select v-model="formDialogMulti.cycl"
                         filterable
                         remote
                         @change="dialogRemoteCyclid"
                         :remote-method="dialogRemoteCycl"
                         placeholder="请选择承运车辆">
                <el-option
                  v-for="item in dialogCreate.searchCph"
                  :key="item.cyclid"
                  :label="item.cycl"
                  :value="item.cyclid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogMultiSave">保存</el-button>
    </s-dialog>
  </div>
</template>
<script>
  import {AutoVue, AutoPromise, GetLodop, FormatterTime} from '~/plugins/Tools';
  import Config from '~/config';
  let {
    PublicImageServer,
  } = Config;
  function __formTest () {
    return {
      xbh: { value: '', rule: [], search: true },
      bz: { value: '', rule: [], search: false },
      sl: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      // zjsj: { value: '', type: 'Date', rule: [ 'vNull__change' ], cRemarks: '' },
    };
  }
  function __form1 () {
    return {
      sl: { value: '', rule: [ 'vNull' ], cRemarks: '' },
    };
  }
  function __formHelpWeight () {
    return {
      xbh: { value: '', rule: [], search: true },
      bz: { value: '', rule: [], search: false },
      sl: { value: '', rule: [ 'vNull' ], cRemarks: '' },
      zjsj: { value: '', type: 'Date', rule: [ 'vNull__change' ], cRemarks: '' },
    };
  }
  function __formCreate () {
    return {
      cyrmc: { value: '', rule: [ 'vNull__change' ] },
      cycl: { value: '', rule: [ 'vNull__change' ] },
    };
  }
  function __formMulti () {
    return {
      cyrmc: { value: '', rule: [ 'vNull__change' ] },
      cycl: { value: '', rule: [ 'vNull__change' ] },
    };
  }
  function __formIssued () {
    return {
      account: { value: '', rule: [ 'vNull__change' ], cRemarks: '' },
      ryid: { value: '', rule: ['vNull__change'], cRemarks: [] },
    };
  }
  function __formEdit () {
    return {
      bz: { value: '', rule: [], cRemarks: '' },
      kddh: { value: '', rule: [], cRemarks: [] },
      fhfs: { value: '', rule: [], cRemarks: [] },
      yf: { value: '', rule: [], cRemarks: [] },
      sjzl: { value: '', rule: [], cRemarks: [] },
    };
  }
  export default AutoVue({
    name: 'outOperation_check-FEcarWms',
    head: {
      'title': '协助发货',
      'meta': [
        {'hid': 'description', 'name': 'description', 'content': '乐速科技平台 协助发货 查看协助发货信息'},
      ],
    },
    store: ['USER', 'DICTIONARY_shelvesTask', 'SHELVESTASK', 'DICTIONARY_assistGoods', 'ASSISTGOODS'],
    data: {
      header: {
        'Content-Disposition': 'attachment',
      },
      dzcselect: '192.168.30.89:11001',
      cyslb: '申通',
      options: [
        {
          value: '192.168.30.89:11001',
          label: '电子秤(192.168.30.89)',
        }, {
          value: '192.168.30.18:11002',
          label: '电子秤(192.168.30.18)',
        }],
      sjzlinput: '',
      mxid: '',
      table: {
        column: [
          {
            label: '发起部门',
            prop: 'fqbm',
            minWidth: '0px',
            search: false,
          },
          {
            label: '发起人',
            prop: 'fqr',
            minWidth: '0px',
            search: true,
          },
          {
            label: '用途',
            prop: 'yt',
            minWidth: '0px',
            search: false,
          },
          {
            label: '流水号',
            prop: 'lsh',
            minWidth: '0px',
            search: true,
          },
          {
            label: '订单号',
            prop: 'ddh',
            minWidth: '0px',
            search: true,
          },
          { label: '下发状态',
            prop: 'show_xfzt',
            minWidth: '0px',
            cRemarks: '下发状态 0未下发 1已下发',
            elTag: {
              filterType: function (value) {
                return value === '未激活' ? 'danger' : 'success';
              },
            },
            search: true },
          {
            label: '装车单编号',
            prop: 'zcdbh',
            minWidth: '0px',
            search: true,
          },
          {
            label: '等待合并发运单号',
            prop: 'ddhbfydh',
            minWidth: '0px',
            search: false,
          },
          {
            label: '发货方式',
            prop: 'fhfs',
            minWidth: '0px',
            search: false,
          },
          {
            label: '运费承担方',
            prop: 'yfcdf',
            minWidth: '0px',
            search: false,
          },
          {
            label: '收货人姓名',
            prop: 'shrxm',
            minWidth: '0px',
            search: false,
          },
          {
            label: '收货人国家',
            prop: 'shrgj',
            minWidth: '0px',
            search: false,
          },
          {
            label: '省份',
            prop: 'sf',
            minWidth: '0px',
            search: false,
          },
          {
            label: '城市',
            prop: 'cs',
            minWidth: '0px',
            search: false,
          },
          {
            label: '县/区',
            prop: 'xq',
            minWidth: '0px',
            search: false,
          },
          {
            label: '收货地址',
            prop: 'shdz',
            minWidth: '0px',
            search: false,
          },
          {
            label: '联系电话',
            prop: 'lxdh',
            minWidth: '0px',
            search: false,
          },
          {
            label: '运费',
            prop: 'yf',
            minWidth: '0px',
            search: false,
          },
          {
            label: '支付日期',
            prop: 'zfrq',
            minWidth: '0px',
            search: false,
          },
          {
            label: '快递单号',
            prop: 'kddh',
            minWidth: '0px',
            search: false,
          },
          {
            label: '产品名称',
            prop: 'cpmc',
            minWidth: '0px',
            search: false,
          },
          {
            label: '数量',
            prop: 'sl',
            minWidth: '0px',
            search: false,
          },
          {
            label: '规格',
            prop: 'gg',
            minWidth: '0px',
            search: false,
          },
          {
            label: '单位',
            prop: 'dw',
            minWidth: '0px',
            search: false,
          },
          {
            label: '产品类别',
            prop: 'cplb',
            minWidth: '0px',
            search: false,
          },
          {
            label: '单价',
            prop: 'dj',
            minWidth: '0px',
            search: false,
          },
          {
            label: '特定物流单号',
            prop: 'tdwldh',
            minWidth: '0px',
            search: false,
          },
          {
            label: '货号',
            prop: 'hh',
            minWidth: '0px',
            search: false,
          },
          {
            label: '发货摘要',
            prop: 'fazy',
            minWidth: '0px',
            search: false,
          },
          {
            label: '备注',
            prop: 'bz',
            minWidth: '0px',
            search: false,
          },
        ],
        data: [ /* {
          hpbh: '20160502',
          hpmc: '王小虎',
          sl: '1518 弄',
          xbh: '1',
        } */ ],
        key: 'id',
        tableColumn: 12,
        url: '/wmsassistdelivery/list',
        total: 0,
      },
      dialogCreate: {
        title: '选择',
        wmsloading: [],
        searchCph: [],
        row: {},
      },
      formDialogCreate: __formCreate(),
      dialogMulti: {
        title: '选择',
        wmsloading: [],
        searchCph: [],
        row: {},
      },
      formDialogMulti: __formMulti(),
      dialogUpload: {},
      formDialog: __formTest(),
      formDialog1: __form1(),
      dialog: {
        title: '修改',
        row: {},
      },
      dialogEdit: {
        title: '修改',
        row: {},
      },
      formDialogEdit: __formEdit(),
      dialogHelpWeight: {
        title: '协助称重',
        row: {},
      },
      formHelpWeight: __formHelpWeight(),
      dialogIssued: {
        title: '下发',
        wmsqualityinspectionlist: '',
        row: {},
      },
      formDalogIssued: __formIssued(),
    },
    transition: 'slide-fade',
    methods: {
      dialogMultiInit () {
        this.formDialogMulti = {
          ...this.formDialogMulti,
          ...this.ObjectClone(__formMulti()),
        };
        this.resetFields('formDialogMulti');
      },
      // 多选 装车单
      async dialogMultiOpen (row) {
        await AutoPromise([
          async () => {
            if (this.dialogCreate.wmsloading.length === 0) {
              this.dialogCreate.wmsloading = await this.post('/wmsloading/searchCyr', {
              });
            }
          },
        ]);
        this.dialogMulti.visible = true;
      },
      // 保存
      async dialogMultiSave () {
        this.VALIDATE('formDialogMulti', async option => {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('请至少选择一条单据！', '提示');
          }
          let wmsLoadingDetailedList = [];
          this.table.multipleSelection.forEach(({id}) => {
            wmsLoadingDetailedList.push({'fyid': id});
          });
          option.wmsLoadingDetailedList = wmsLoadingDetailedList;
          try {
            option.cyrid = this.dialogCreate.row.cyrid;
            option.cyrmc = this.dialogCreate.row.cyrmc;
            option.cycl = this.dialogCreate.row.cycl;
            await this.post('/wmsloading/assistAddLoading', option);
            this.tableWatch('table');
            this.dialogMultiInit();
            this.dialogMulti.visible = false;
          } catch (err) {
            console.log(err);
          }
        });
      },
      // 发运任务
      tableShipment (row) {
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将发运选择的发运订单', '确认发运？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsassistdelivery/pcfy', {
                ids,
              });
              this.tableWatch('table');
            } catch (err) {
              console.log(err);
            }
          });
      },
      formatterTime: FormatterTime,
      tableDelete (row) {
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将删除选择的数据', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              await this.post('/wmsassistdelivery/del', {
                ids,
              });
              this.table.multipleSelection.length = 0;
              console.log('length:' + this.table.multipleSelection.length);
              this.tableWatch('table');
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      dialogUploadInit () {},
      async dialogUploadOpen () {
        this.dialogUpload.visible = true;
      },
      dialogUploadBefore (file) {
        var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
        let ifchinese = reg.test(file.name);
        /* if (ifchinese) {
          this.$message.error('文件名不能包含中文!');
        } */
        let isExcel = false;
        if (file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || file.type !== 'application/vnd.ms-excel') {
          isExcel = true;
        };
        const isLt = file.size / 1024 / 1024 < 50;
        if (!isExcel) {
          this.$message.error('上传文件只能是 Excel 格式!');
        }
        if (!isLt) {
          this.$message.error('上传头像图片大小不能超过 50MB!');
        }
        return (isExcel) && isLt;
      },
      async dialogUploadSuccess (res, file, fileList) {
        let filepath = PublicImageServer.src + '/' + 'excel/zxwms/shipment';
        console.log(filepath + '/' + encodeURI(res.filename));
        try {
          await this.post('/wmsassistdelivery/upload', {
            filepath: filepath + '/' + encodeURI(res.filename),
          });
          this.tableWatch('table');
        } finally {
          // this.del(this.action + '/' + res.filename);
        }
      },
      dialogUploadError (err) {
        console.log('err', err);
      },
      dialogUploadSubmit () {
        this.$refs.upload.submit();
      },
      dialogUploadSave () {
        this.dialogUploadInit();
        this.dialogUpload.visible = false;
      },
      dialogInit () {
        this.dialog.row = {};
        this.formDialog = {
          ...this.formDialog,
          ...this.ObjectClone(__formTest()),
        };
        this.resetFields('formDialog');
        this.dialogHelpWeight.visible = false;
        this.mxid = '';
        this.sjzlinput = '';
      },
      tableEdit (row) {
        this.dialogOpen('PUT', row);
      },
      helpWeight (row) {
        this.mxid = row.id;
        this.dialogHelpWeight.visible = true;
      },
      async dialogOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        switch (type) {
        case 'ADD':
          this.dialog.title = '新增';
          this.formDialog.id = 0;
          break;
        case 'PUT':
          this.dialog.title = '修改';
          this.formDialog = {
            ...this.formDialog,
            ...this.ObjectClone(__formTest(), row),
          };
          this.dialog.row = row;
          break;
        }
        this.dialog.visible = true;
      },
      dialogSave () {
        if (this.dialog.title === '修改') {
          this.VALIDATE('formDialog', async option => {
            try {
              option.id = this.dialog.row.id;
              await this.post('/wmsassistdelivery/edit', option);
              this.tableWatch('table');
              this.dialogInit();
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          });
        }
      },
      dialogEditInit () {
        this.formDialogEdit = {
          ...this.formDialogEdit,
          ...this.ObjectClone(__formEdit()),
        };
      },
      dialogEditOpen (row) {
        this.formDialogEdit = {
          ...this.formDialogEdit,
          ...this.ObjectClone(__formEdit(), row),
        };
        this.dialogEdit.row = row;
        this.dialogEdit.visible = true;
      },
      dialogEditSave () {
        this.VALIDATE('formDialogEdit', async option => {
          try {
            option.id = this.dialogEdit.row.id;
            await this.post('/wmsassistdelivery/edit', option);
            this.tableWatch('table');
            this.dialogEditInit();
            this.dialogEdit.visible = false;
          } catch (err) {
            console.log(err);
          }
        });
      },
      async printpaper () {
        let sjzl = this.sjzlinput;
        let id = this.mxid;
        if (this.sjzlinput === '') {
          return this.$alert('实际数量不能为空！', '提示');
        }
        if (this.cyslb === '申通') {
          try {
            let postdata = await this.get(`/wmsassistdelivery/print/${id}/${sjzl}/${1}`);
            let url = postdata.data[0];
            let LODOP = GetLodop();
            LODOP.PRINT_INIT('打印快递面单');
            LODOP.ADD_PRINT_URL(0, 0, 746, '100%', url);
            LODOP.SET_PRINT_STYLEA(0, 'HOrient', 3);
            LODOP.SET_PRINT_STYLEA(0, 'VOrient', 3);
            setTimeout(() => {
              LODOP.PREVIEW();
            }, 3000);
          } catch (err) {
            console.log(err);
          }
        } else {
          try {
            let postdata = await this.get(`/wmsassistdelivery/print/${id}/${sjzl}/${2}`);
            let url = postdata.data[0];
            let LODOP = GetLodop();
            LODOP.PRINT_INIT('打印快递面单');
            LODOP.ADD_PRINT_URL(0, 0, 746, '100%', url);
            LODOP.SET_PRINT_STYLEA(0, 'HOrient', 3);
            LODOP.SET_PRINT_STYLEA(0, 'VOrient', 3);
            setTimeout(() => {
              LODOP.PREVIEW();
            }, 3000);
          } catch (err) {
            console.log(err);
          }
        }
      },
      webSocketOpen (ip) {
        let socket = new WebSocket('ws://' + ip + '/websocket');
        let _this = this;
        socket.onopen = function (event) {
          console.log('socket listening');
          // socket.send('socket listening');
          socket.onmessage = function (event) {
            console.log('接收到消息' + event.data);
            _this.sjzlinput = event.data;
          };
        };
      },
      selectchange () {
        this.webSocketOpen(this.dzcselect);
      },
      sjzlchange () {},
      dialogCreateInit () {
        this.formDialogCreate = {
          ...this.formDialogCreate,
          ...this.ObjectClone(__formCreate()),
        };
        this.resetFields('formDialogCreate');
      },
      async dialogCreateOpen (row) {
        await AutoPromise([
          async () => {
            if (this.dialogCreate.wmsloading.length === 0) {
              this.dialogCreate.wmsloading = await this.post('/wmsloading/searchCyr', {
              });
            }
          },
        ]);
        this.dialogCreate.row = row;
        this.dialogCreate.visible = true;
      },
      async dialogRemoteCycl (query, id) {
        this.dialogCreate.searchCph = await this.post('/wmsloading/searchCph', { cyrid: this.dialogCreate.row.cyrid, cph: query });
      },
      dialogRemoteCyrmc () {},
      dialogRemoteCyclid () {},
      async dialogRemoteCyrid () {
        this.dialogCreate.wmsloading.forEach(value => {
          this.dialogCreate.row.cyrid = value.cyrid;
          this.dialogCreate.row.cyrmc = value.cyrmc;
          console.log('id:' + this.dialogCreate.row.cyrid);
        });
        let str = '';
        this.dialogCreate.searchCph = await this.post('/wmsloading/searchCph', { cyrid: this.dialogCreate.row.cyrid, cph: str });
      },
      async dialogCreateSave () {
        this.VALIDATE('formDialogCreate', async option => {
          option.cyrid = this.dialogCreate.row.cyrid;
          option.cyrmc = this.dialogCreate.row.cyrmc;
          option.cycl = this.dialogCreate.row.cycl;
          let json = {
            ...option,
            wmsLoadingDetailedList: [
              {
                fyid: this.dialogCreate.row.id,
              },
            ],
          };
          try {
            await this.post('/wmsloading/assistAddLoading', json);
            this.dialogCreateInit();
            this.tableWatch('table');
            this.dialogCreate.visible = false;
          } catch (err) {
            console.log(err);
          }
        });
      },
      async tablePrint (row) {
        console.log('test');
        let ids = [];
        let index = 0;
        let trs = [''];
        if (row) {
          ids.push(row.id);
        } else {
          if (this.table.multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this.table.multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        try {
          let {contentList} = await this.post('/wmsloading/assistPrintLoading/', {
            ids,
          });
          for (let j = 0; j < contentList.length; j++) {
            for (let i = 0; i < contentList[j].wmsLoadingDetailedList.length; i++) {
              trs[j] += `
                  <tr>
                    <td width="50px"  style="border: 1px solid #000;height:18px"><b>${i + 1}</b></td>
                    <td width="180px" style="border: 1px solid #000;height:18px"><b>${contentList[j].wmsLoadingDetailedList[i].wlbh}</b></td>
                    <td width="180px" style="border: 1px solid #000;height:18px"><b>${contentList[j].wmsLoadingDetailedList[i].xbh}</b></td>
                    <td width="180px" style="border: 1px solid #000;height:18px"><b>${contentList[j].wmsLoadingDetailedList[i].shr}</b></td>
                  </tr>`;
            }
          }
          this.$confirm('您将打印装车单信息。', '确认打印？', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
          }).then(() => {
            let LODOP = GetLodop();
            LODOP.PRINT_INIT('打印装车单信息');
            this.tableWatch('table');
            // console.log('1:' + JSON.stringify(contentList[0].wmsLoadingDetailedList.length));
            for (let item of contentList) {
              LODOP.NewPage();
              LODOP.ADD_PRINT_TEXT(51, 261, 268, 42, '大连双迪发运装载单');
              LODOP.SET_PRINT_STYLEA(0, 'FontSize', 20);
              LODOP.SET_PRINT_STYLEA(0, 'Horient', 2);
              LODOP.ADD_PRINT_BARCODE(120, 230, 400, 78, 'EAN128B', item.zcdbh);
              LODOP.SET_PRINT_STYLEA(0, 'Horient', 2);
              LODOP.ADD_PRINT_TEXT(235, 123, 160, 24, '物流单数');
              LODOP.ADD_PRINT_TEXT(235, 188, 160, 24, item.zds);
              LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              LODOP.ADD_PRINT_TEXT(286, 123, 160, 25, '承运商');
              LODOP.ADD_PRINT_TEXT(286, 188, 160, 25, item.cyrmc);
              LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              LODOP.ADD_PRINT_TEXT(233, 327, 252, 25, '总单数');
              LODOP.ADD_PRINT_TEXT(233, 392, 252, 25, item.zxs);
              LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              LODOP.ADD_PRINT_TEXT(285, 325, 254, 25, '承运车辆');
              LODOP.ADD_PRINT_TEXT(282, 390, 254, 25, item.cycl);
              LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              LODOP.ADD_PRINT_TABLE(334, 125, 500, 280, `<table border=0 cellSpacing=0 cellPadding=0  width="100%">
                  <tr>
                    <td width="50px"  style="border: 1px solid #000;height:18px"><b>序号</b></td>
                    <td width="180px" style="border: 1px solid #000;height:18px"><b>物流单号</b></td>
                    <td width="180px" style="border: 1px solid #000;height:18px"><b>订单号</b></td>
                    <td width="180px" style="border: 1px solid #000;height:18px"><b>收货人</b></td>

                  </tr>` +
                trs[index] + `<tfoot>
                  <tr>
                  <th colspan="2" style="border: none; height: 50px">双迪代表</th>
                  <th colspan="2" style="border: none; height: 50px">承运人</th>
                  </tr>
                   <tr>
                  <th colspan="2" style="border: none; height: 50px">日期</th>
                  <th colspan="2" style="border: none; height: 50px">日期</th>
                  </tr>

                  </tfoot></table>`);
              LODOP.ADD_PRINT_TEXT(233, 599, 169, 25, '打印日期');
              LODOP.ADD_PRINT_TEXT(230, 660, 169, 25, this.formatterTime(new Date(), 3));
              LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              // LODOP.ADD_PRINT_TEXT(385, 123, 257, 24, '双迪代表');
              // LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              // LODOP.ADD_PRINT_TEXT(550, 123, 259, 20, '日期');
              // LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              // LODOP.ADD_PRINT_TEXT(500, 450, 238, 20, '承运人');
              // LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              // LODOP.ADD_PRINT_TEXT(550, 450, 238, 20, '日期');
              // LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11);
              index++;
            }
            // CreatePrintPage();
            // 设计
            // LODOP.PRINT_DESIGN();
            LODOP.PREVIEW();
          });
        } catch (err) {
          console.log(err);
        };
      },
      dialogIssuedInit () {
        this.formDalogIssued = {
          ...this.formDalogIssued,
          ...this.ObjectClone(__formIssued()),
        };
        this.resetFields('formDalogIssued');
      },
      // 下发 发运任务
      async dialogIssuedOpen (row) {
        await AutoPromise([
          async () => {
            if (!this.DICTIONARY_shelvesTask) {
              await this.USE('DICTIONARY_shelvesTask');
            }
          },
        ]);
        this.dialogIssued.row = row;
        this.dialogIssued.visible = true;
      },
      // 下发货 保存
      dialogIssuedSave () {
        this.VALIDATE('formDalogIssued', async option => {
          let json = {
            id: this.formDalogIssued.ryid + '',
            ids: [this.dialogIssued.row.id],
          };
          try {
            await this.post('/wmsassistdelivery/xfpda', json);
            this.tableWatch('table');
            this.dialogIssuedInit();
            this.dialogIssued.visible = false;
          } catch (err) {
            console.log(err);
          }
        });
      },
    },
    computed: {
      action: function () {
        return PublicImageServer.src + '/' + PublicImageServer.upload + '/excel/zxwms/shipment';
      },
    },
    mounted: async function () {
      console.log('assistgoods');
      this.tableWatch('table');
      this.webSocketOpen(this.dzcselect);
      if (!this.DICTIONARY_assistGoods) {
        await this.USE('DICTIONARY_assistGoods');
      }
    },
    watch: {
      'formDalogIssued.account': async function (account) {
        this.formDalogIssued.arr = '';
        if (account.length !== 0 && account === '0') {
          this.dialogIssued.wmsqualityinspectionlist = await this.post('/wmsqualityinspectionlist/selectYh', {});
        }
        if (account.length !== 0 && account === '1') {
          let {contentList} = await this.post('/wmsqualityinspectionlist/selectPDADLByHz', {});
          this.dialogIssued.wmsqualityinspectionlist = contentList;
        }
      },
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
  .headertype {
    color:#1bab8b;
  }
</style>

<style lang="scss">

</style>
